/* 
 * Created on 2007-4-22
 * Last modified on 2007-4-22
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.image;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.apache.log4j.Logger;

public abstract class ImageOperate {
	
	private static final Logger logger = Logger.getLogger(ImageOperate.class);
	
	public static final int JPEG = 1;
	
	public static final int GIF = 2;
	
	/**
	 * 剪裁AND缩放图片
	 * @param bis
	 * @param filePathAndName
	 * @param w
	 * @param h
	 * @param x
	 * @param y
	 * @param x_w
	 * @param y_h
	 * @return
	 */
	public abstract boolean clip(BufferedInputStream bis, String filePathAndName
    		, int w, int h
    		, int x, int y, int x_w, int y_h);
	
	public boolean clip(String path, String filePathAndName
    		, int w, int h
    		, int x, int y, int x_w, int y_h){
		boolean bea = false;
		try {
			FileInputStream fis = new FileInputStream(new File(path));
			BufferedInputStream bis = new BufferedInputStream (fis);
			bea = clip(bis,filePathAndName,w,h,x,y,x_w,y_h);
		} catch (FileNotFoundException e) {
			logger.error(e.toString());
		}
		return bea;
	}
	
	public abstract boolean incise(File file, String filePathAndName, int w, int h
    		, int x, int y, int x_w, int y_h);
	
	
	public boolean incise(String path, String filePathAndName, int w, int h
    		, int x, int y, int x_w, int y_h){
		return this.incise(new File(path),filePathAndName,w,h,x,y,x_w,y_h);
	}
	
	/**
	 * 缩放图片
	 * @param w
	 * @param h
	 * @param opath
	 * @param npath
	 * @return
	 */
	public abstract boolean narrowOrEnlarge(String opath, String npath, int w, int h);
	
	/**
	 * 给图片加水印
	 * @param opath 原图路径
	 * @param npath	加水印后的新路径
	 * @param wpath 水印图路径
	 * @param w
	 * @param h
	 * @return
	 */
	public abstract boolean watermark(String opath, String npath, String wpath);
	
	/**
	 * 
	 * @param opath
	 * @param npath
	 * @param wpath
	 * @param minwidth 小于此宽度的图片不加水印
	 * @param minheight 小于此高度的图片不加水印
	 * @return
	 */
	public abstract boolean watermark(String opath, String npath, String wpath, int minwidth, int minheight);
}
